package net.display;


import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import net.bo.KUtilisateur;
import net.ko.displays.KObjectDisplay;
import net.ko.http.views.KHtmlFieldControl;
import net.ko.http.views.KPageList;
import net.ko.kobject.KObject;
import net.ko.types.HtmlControlType;


public class DisplayUtilisateurAAffect extends KObjectDisplay {
	
	@Override
	public String showInList(KObject ko, String memberName,HttpServletRequest request) {
		String result=super.showInList(ko, memberName,request);
		KUtilisateur user=(KUtilisateur) ko;
		if("cocher".equals(memberName)){
			result="<input type='checkbox' id='"+user.getId()+"'"+"value='"+user.getId()+"'"+" />";
		}
		return result;
	}
	
	@Override
	public void beforeLoading(Class<? extends KObject> clazz, KPageList list,
			HttpServletRequest request) {
		String idPLan=request.getSession().getAttribute("plan")+"";
		list.setSql("Select * from utilisateur where id not in(Select idUtilisateur from affectation where idPlan ="+idPLan+")");	
		super.beforeLoading(clazz, list, request);		
	}

	@Override
	public String getZone(String zoneName, KPageList list,
			HttpServletRequest request) {
		SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
		String result= super.getZone(zoneName, list, request);
		if("dateD".equals(zoneName)){
			KHtmlFieldControl dateD=new KHtmlFieldControl("Date début :",df.format( new Date() ), "dateD", "dateD", HtmlControlType.khcDateCmb);
			dateD.setRequired(true);
			result=dateD.toString();
		}
		if("dateF".equals(zoneName)){
			KHtmlFieldControl dateF=new KHtmlFieldControl("Date fin :",df.format( new Date() ), "dateF", "dateF", HtmlControlType.khcDateCmb);
			dateF.setRequired(true);
			result=dateF.toString();
		}
		return result;
	}
}

